knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)

library(ggplot2)
library(lme4)
library(WRS2)
library(knitr)
library(reshape2)
library(plyr)
library(dplyr)
library(stringr)
library(sjPlot)
library(cowplot)
library(fmsb)
library(ggthemes)
library(effects)
library(grid)
library(gridExtra)
#library(magick)
library(data.table)
### FLANKER ### 

# set working directory - where R will look for our data

setwd("/Volumes/EEG/CategoryLearning/Data/Exp2/Flanker")

# create a list of file names for R to search through when compiling data

file_names_Flanker <- dir(pattern = "flanker-[0-9+].*.csv", recursive=TRUE)

# create an empty data frame into which the compiled data will be entered

raw_Flanker <- data.frame(matrix(vector(), 0, 11,
                           dimnames=list(c(),
                                         c("subnum", "block", "trial", "practice", "targdir", "flankercoherence", 
                                           "flankerdir", "time0", "resp", "corr", "rt"))), 
                  stringsAsFactors=FALSE)


# for each file in our file names structure, add it to an empty data frame 
# and bind to the raw empty data frame produced above

for (i in file_names_Flanker) {
  data_Flanker <- fread(i, header = TRUE, sep = ",", na.strings="NR")
  data_Flanker <- `colnames<-`(data_Flanker, c("subnum", "block", "trial", "practice", "targdir", "flankercoherence", 
                                               "flankerdir", "time0", "resp", "corr", "rt"))
  raw_Flanker <- rbind(raw_Flanker, data_Flanker)
}

### TOL ###

# set working directory - where R will look for our data

setwd("/Volumes/EEG/CategoryLearning/Data/Exp2/ToL")

# create a list of file names for R to search through when compiling data

file_names_TOL <- dir(pattern = "tol-summary-[0-9+].*.csv", recursive=TRUE)

# create an empty data frame into which the compiled data will be entered

raw_TOL <- data.frame(matrix(vector(), 0, 16,
                           dimnames=list(c(),
                                         c("sub", "trial", "size", "shortest", "startlab", "endlab",
                                           "startconf", "endconf", "success", "tries", "score", "steps",
                                           "roundstart", "starttime", "firsttime", "time"))), 
                  stringsAsFactors=FALSE)

# for each file in our file names structure, add it to an empty data frame 
# and bind to the raw empty data frame produced above

for (i in file_names_TOL) {
  data_TOL <- fread(i, header = TRUE, sep = ",", na.strings="NR")
  data_TOL <- `colnames<-`(data_TOL, c("sub", "trial", "size", "shortest", "startlab", "endlab",
                                           "startconf", "endconf", "success", "tries", "score", "steps",
                                           "roundstart", "starttime", "firsttime", "time"))
  raw_TOL <- rbind(raw_TOL, data_TOL)
}


### SWITCHER ### 

# set working directory - where R will look for our data

setwd("/Volumes/EEG/CategoryLearning/Data/Exp2/Switcher")

# create a list of file names for R to search through when compiling data

file_names_Switcher <- dir(pattern = "switch-summary-[0-9+].*.csv", recursive=TRUE)

# create an empty data frame into which the compiled data will be entered

raw_Switcher <- data.frame(matrix(vector(), 0, 11,
                           dimnames=list(c(),
                                         c("subNum", "timestamp", "testtype", "numcues", "numerr", 
                                           "matchlast", "matchany", "tooslow", "waittime", "perftime", "medtime"))), 
                  stringsAsFactors=FALSE)

# for each file in our file names structure, add it to an empty data frame 
# and bind to the raw empty data frame produced above

for (i in file_names_Switcher) {
  data_Switcher <- fread(i, header = TRUE, sep = ",", na.strings="NR")
  data_Switcher <- `colnames<-`(data_Switcher, c("subNum", "timestamp", "testtype", "numcues", "numerr", 
                                           "matchlast", "matchany", "tooslow", "waittime", "perftime", "medtime"))
  raw_Switcher <- rbind(raw_Switcher, data_Switcher)
}
### FLANKER ###

#raw_Flanker produces a data frame wherein...
# targdir = -1 means left; +1 means right
# flankerdir = same coding
# flankercoherence = -1 means mismatch; 0 means neutral, +1 means match

## SUMMARIZING ACCURACY AND RT ##

#remove practice trials
data_Flanker <- subset(raw_Flanker, practice==0)

## QUICK CLEAN 

# fix subnums

data_Flanker$subnum[data_Flanker$subnum==1] <- 8076
data_Flanker$subnum[data_Flanker$subnum==7] <- 8001
data_Flanker$subnum[data_Flanker$subnum==9] <- 8002
data_Flanker$subnum[data_Flanker$subnum==4] <- 8003
data_Flanker$subnum[data_Flanker$subnum==11] <- 8114
data_Flanker$subnum[data_Flanker$subnum==21] <- 8021
data_Flanker$subnum[data_Flanker$subnum==29] <- 8036
data_Flanker$subnum[data_Flanker$subnum==44] <- 8054
data_Flanker$subnum[data_Flanker$subnum==50] <- 8064
data_Flanker$subnum[data_Flanker$subnum==84] <- 8124
data_Flanker$subnum[data_Flanker$subnum==86] <- 8125
data_Flanker$subnum[data_Flanker$subnum==87] <- 8126

#remoove non-responses
data_Flanker <- subset(data_Flanker, resp=="<lshift>" | resp=="<rshift>")

#summarize data by targdir and flankercoherence
data_Flanker_sum <- with(data_Flanker, aggregate(list(corr, rt), list(flankercoherence), 
                                                      mean, na.rm=TRUE))
colnames(data_Flanker_sum) <- c("flankerCoherence", "acc", "rt")
kable(data_Flanker_sum, format="html")
flankerCoherence acc rt
-1 0.8867080 464.9551
0 0.9822616 401.1182
1 0.9767958 418.2730
NA 0.9656352 423.6189
data_Flanker_sub <- with(data_Flanker, aggregate(list(corr, rt), list(subnum, flankercoherence),
                                                 mean, na.rm=TRUE))
colnames(data_Flanker_sub) <- c("subject", "flankerCoherence", "acc", "rt")

data_Flanker_sub.1 <- subset(data_Flanker_sub, flankerCoherence==-1)

hist(data_Flanker_sub.1$acc)

hist(data_Flanker_sub.1$rt)

## PROCESSING AND CALCULATING FLANKER EFFECTS

#remove incorrect responses
data_Flanker_cor <- subset(data_Flanker, corr==1)

#subset for only coherent and incoherent trials
data_Flanker_trim <- subset(data_Flanker_cor, flankercoherence=="-1" | flankercoherence=="1")
data_Flanker_trim$flankercoherence <- ifelse(data_Flanker_trim$flankercoherence=="1", "flank_Congruent", "flank_Incongruent")

#reduce to by-subject data-frame

data_Flanker_trim_sub <- with(data_Flanker_trim, aggregate(list(rt), list(subnum, flankercoherence),
                                                 mean, na.rm=TRUE))
colnames(data_Flanker_trim_sub) <- c("subject", "flank_Coherence", "flank_rt")

#melt and cast for calculating flanker effect

data_Flanker_trim_melt <- melt(data_Flanker_trim_sub, id.vars=c("subject", "flank_Coherence"))
data_Flanker_trim_cast <- dcast(data_Flanker_trim_melt, subject ~ flank_Coherence)

data_Flanker_trim_cast$flank_eff <- data_Flanker_trim_cast$flank_Incongruent - data_Flanker_trim_cast$flank_Congruent
hist(data_Flanker_trim_cast$flank_eff)

### TOL ###

#sub indicates the subject code
#trial indicates which trial in the test
#size is the number of disks in the problem
#shortest is the least number of moves needed to solve the problem (may not be available in all tests)
#startlab is a node within an internal matrix indicating the starting configuration
#endlab is a nod within an internal matrix indicating ending configuration.
#startconf is the configuration of disks at the beginning
#endconf is the configuration at the end.
#success is whether the participant completed the task (may be 0 when a time or move limit is used)
#tries is how many attempts were made (how many times it was reset, not used in all versions)
#score is a running total score, which is just one point per number of disks in correctly solved problems
#steps is the number of moves used to solve the problem
#roundstart is the absolute timer time when the problem was given (in ms)
#starttime is a second measure of this that resets if multiple attempts are given
#firstime is the first move time in ms
#time is the total time for the problem in ms, including first move time.

## SUMMARIZE DATA BY SUBJECT AND TRIAL ##

#exclude subject 9, who for some reasoon completed 30 trials of TOL...
data_TOL <- subset(raw_TOL, sub != 9 & sub != 8057)

#rename 

data_TOL$sub[data_TOL$sub==1] <- 8076
data_TOL$sub[data_TOL$sub==7] <- 8001
data_TOL$sub[data_TOL$sub==9] <- 8002
data_TOL$sub[data_TOL$sub==4] <- 8003
data_TOL$sub[data_TOL$sub==11] <- 8114
data_TOL$sub[data_TOL$sub==21] <- 8021
data_TOL$sub[data_TOL$sub==29] <- 8036
data_TOL$sub[data_TOL$sub==44] <- 8054
data_TOL$sub[data_TOL$sub==50] <- 8064
data_TOL$sub[data_TOL$sub==84] <- 8124
data_TOL$sub[data_TOL$sub==86] <- 8125
data_TOL$sub[data_TOL$sub==87] <- 8126

#collapse data for individual subject data
data_TOL_sub <- with(data_TOL, aggregate(list(success, time), list(sub), 
                                         mean, na.rm=TRUE))
colnames(data_TOL_sub) <- c("subject", "TOL_success", "TOL_time")

hist(data_TOL_sub$TOL_success)

hist(data_TOL_sub$TOL_time)

#examine first-trial data only
data_TOL_sub.1 <- with(data_TOL, aggregate(list(success, time), list(sub, trial), 
                                         mean, na.rm=TRUE))
colnames(data_TOL_sub.1) <- c("subject", "TOL_trial", "TOL_success", "TOL_time")

data_TOL_sub.1 <- subset(data_TOL_sub.1, TOL_trial==1)

#collapse data for trial-level data
data_TOL_trial <- with(data_TOL, aggregate(list(success, firsttime, time), list(trial),
                                           mean, na.rm=TRUE))
colnames(data_TOL_trial) <- c("TOL_trial", "TOL_success", "TOL_first", "TOL_time")

data_TOL_move <- with(data_TOL, aggregate(list(success, time), list(shortest),
                                           mean, na.rm=TRUE))
colnames(data_TOL_move) <- c("TOL_minMoves", "TOL_success", "TOL_time")

#collapse data to overall success rate
data_TOL_success <- with(data_TOL, aggregate(list(success, firsttime, time), list(sub),
                                           mean, na.rm=TRUE))
colnames(data_TOL_success) <- c("subject", "TOL_acc", "TOL_first", "TOL_time")
hist(data_TOL_success$TOL_acc)

#plot data as a function of successes and RTs (a) over time (trials) and (b) over min number of moves
TOLtrialPlot.success <- ggplot(data_TOL_trial, aes(x=TOL_trial, y=TOL_success)) +
  geom_point() + 
  geom_line() + 
  scale_x_continuous(name="trial", breaks=c(1:12)) +
  ggtitle("Success by trial") + 
  ylab("success") +
  theme_few()
TOLtrialPlot.success

TOLtrialPlot.time <- ggplot(data_TOL_trial, aes(x=TOL_trial, y=TOL_time)) +
  geom_point() + 
  geom_line() + 
  scale_x_continuous(name="trial", breaks=c(1:12)) +
  ggtitle("Response time by trial") + 
  ylab("response time") +
  theme_few()
TOLtrialPlot.time

TOLtrialPlot.first <- ggplot(data_TOL_trial, aes(x=TOL_trial, y=TOL_first)) +
  geom_point() + 
  geom_line() + 
  scale_x_continuous(name="trial", breaks=c(1:12)) +
  ggtitle("Response time by trial") + 
  ylab("time to first move") +
  theme_few()
TOLtrialPlot.first

TOLmovePlot.success <- ggplot(data_TOL_move, aes(x=TOL_minMoves, y=TOL_success)) +
  geom_point() + 
  geom_line() + 
  scale_x_continuous(name="moves", breaks=c(1:12)) +
  ggtitle("Success by minimum number of moves (i.e., difficulty)") + 
  ylab("success") +
  theme_few()
TOLmovePlot.success

TOLmovePlot.time <- ggplot(data_TOL_move, aes(x=TOL_minMoves, y=TOL_time)) +
  geom_point() + 
  geom_line() + 
  scale_x_continuous(name="moves", breaks=c(1:12)) +
  ggtitle("Response time by minimum number of moves (i.e., difficulty)") + 
  ylab("response time") +
  theme_few()
TOLmovePlot.time

## ANALYZE DATA FOR MIN MOVES, ETC ##

successMod <- glmer(success ~ (1|sub), data_TOL, binomial)
summary(successMod)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: success ~ (1 | sub)
##    Data: data_TOL
## 
##      AIC      BIC   logLik deviance df.resid 
##   2375.2   2386.2  -1185.6   2371.2     1846 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.8270 -1.0864  0.6007  0.7168  1.2782 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  sub    (Intercept) 0.3187   0.5646  
## Number of obs: 1848, groups:  sub, 153
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.64242    0.06861   9.363   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
successMod.1 <- glmer(success ~ as.factor(shortest) + (1|sub), data_TOL, binomial)
summary(successMod.1)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: success ~ as.factor(shortest) + (1 | sub)
##    Data: data_TOL
## 
##      AIC      BIC   logLik deviance df.resid 
##   2281.4   2309.0  -1135.7   2271.4     1843 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5459 -0.9659  0.4869  0.7146  1.8166 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  sub    (Intercept) 0.3859   0.6212  
## Number of obs: 1848, groups:  sub, 153
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)            1.6447     0.1625  10.119  < 2e-16 ***
## as.factor(shortest)3  -0.6342     0.2012  -3.152  0.00162 ** 
## as.factor(shortest)4  -0.9993     0.1765  -5.663 1.49e-08 ***
## as.factor(shortest)5  -1.5484     0.1759  -8.802  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) as.()3 as.()4
## as.fctr(s)3 -0.718              
## as.fctr(s)4 -0.824  0.659       
## as.fctr(s)5 -0.835  0.663  0.761
### SWITCHER ###
# raw_Switcher produces a dataframe wherein...
# testtype is the main IV of interest, where the different codes indicate the different rounds of the test (1=2-feature, 2=3-feature, 3=3-feature random)
# numcues tells you how many stimuli were on the screen
# numerr is how many errors were made
# matchlast is how many times the error matched the previous feature
# matchany is how many times the error matched on any feature
# tooslow is how often the response was
# waittime is how long they took before making their first move.
# perftime is how long they took once they made their first move to complete the round
# medtime is the median RT in ms for each response (i.e., after the first)
# Of greatest interest are two DVS: perftime and numerr (how long they took and how many mistakes they made. Matchlast records how many times did an error match the previous rule, which is sort of like a perseveration error found in many tasks

# difference score between two different types 

# summarize data by subject, testtype

data_Switcher <- raw_Switcher

data_Switcher$subnum[data_Switcher$subnum==1] <- 8076
data_Switcher$subnum[data_Switcher$subnum==7] <- 8001
data_Switcher$subnum[data_Switcher$subnum==9] <- 8002
data_Switcher$subnum[data_Switcher$subnum==4] <- 8003
data_Switcher$subnum[data_Switcher$subnum==11] <- 8114
data_Switcher$subnum[data_Switcher$subnum==21] <- 8021
data_Switcher$subnum[data_Switcher$subnum==29] <- 8036
data_Switcher$subnum[data_Switcher$subnum==44] <- 8054
data_Switcher$subnum[data_Switcher$subnum==50] <- 8064
data_Switcher$subnum[data_Switcher$subnum==84] <- 8124
data_Switcher$subnum[data_Switcher$subnum==86] <- 8125
data_Switcher$subnum[data_Switcher$subnum==87] <- 8126

data_Switcher_type <- with(data_Switcher, aggregate(list(numerr, perftime, tooslow), 
                                                    list(testtype), 
                                                    mean, na.rm=TRUE))
colnames(data_Switcher_type) <- c("switch_type", "switch_err", "switch_rt", "switch_slow")

switcherTypeErr <- ggplot(data_Switcher_type, aes(x=as.factor(switch_type), y=switch_err)) +
  geom_bar(stat="identity", width=0.4) + 
  ggtitle("Number of errors by trial type (1=2-feature, 2=3-feature, 3=3-feature random)") + 
  ylab("Average number of errors") + 
  xlab("Trial type") +
  theme_few()
switcherTypeErr

switcherTypeRT <- ggplot(data_Switcher_type, aes(x=as.factor(switch_type), y=switch_rt)) +
  geom_bar(stat="identity", width=0.4) + 
  ggtitle("Response time by trial type (1=2-feature, 2=3-feature, 3=3-feature random)") + 
  ylab("Response time") + 
  xlab("Trial type") +
  theme_few()
switcherTypeRT

switcherTypeSlow <- ggplot(data_Switcher_type, aes(x=as.factor(switch_type), y=switch_slow)) +
  geom_bar(stat="identity", width=0.4) + 
  ggtitle("Slow responses by trial type (1=2-feature, 2=3-feature, 3=3-feature random)") + 
  ylab("# of too-slow responses") + 
  xlab("Trial type") +
  theme_few()
switcherTypeSlow

data_Switcher_sub <- with(data_Switcher, aggregate(list(numerr, perftime, tooslow), 
                                                    list(subNum, testtype), 
                                                    mean, na.rm=TRUE))
colnames(data_Switcher_sub) <- c("subject", "switch_type", "switch_err", "switch_rt", "switch_slow")

data_Switcher_melt <- melt(data_Switcher_sub, id.vars=c("subject", "switch_type"))
data_Switcher_cast <- dcast(data_Switcher_melt, subject ~ switch_type + variable)

colnames(data_Switcher_cast) <- c("subject", "switch_err_1", "switch_rt_1", "switch_slow_1", 
                                  "switch_err_2", "switch_rt_2", "switch_slow_2",
                                  "switch_err_3", "switch_rt_3", "switch_slow_3")

data_Switcher_cast$switchEff <- data_Switcher_cast$switch_rt_3 - data_Switcher_cast$switch_rt_2
hist(data_Switcher_cast$switchEff)

### COMBINE ALL INTO ONE ###

data_All <- merge(data_Flanker_trim_cast, data_TOL_success, by="subject", all=TRUE)
data_All <- merge(data_All, data_Switcher_cast, by="subject", all=TRUE)   

# run correlations on main measures across tests

flank.TOL.cor <- ggplot(data_All, aes(x=flank_eff, y=TOL_acc)) + 
  geom_point() +
  geom_smooth(method="lm", color="purple") + 
  ggtitle("Correlation between flanker effect and Tower of London overall accuracy") +
  xlab("Flanker effect (Incongruent - Congruent RT)") +
  ylab("Tower of London overall accuracy") +
  theme_few()
flank.TOL.cor

cor.test(data_All$flank_eff, data_All$TOL_acc)
## 
##  Pearson's product-moment correlation
## 
## data:  data_All$flank_eff and data_All$TOL_acc
## t = -0.43796, df = 144, p-value = 0.6621
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.197749  0.126727
## sample estimates:
##         cor 
## -0.03647226
flank.TOLfirst.cor <- ggplot(data_All, aes(x=flank_eff, y=TOL_first)) + 
  geom_point() +
  geom_smooth(method="lm", color="purple") + 
  ggtitle("Correlation between flanker effect and Tower of London first move time") +
  xlab("Flanker effect (Incongruent - Congruent RT)") +
  ylab("Tower of London overall first move time") +
  theme_few()
flank.TOLfirst.cor

flank.TOLtime.cor <- ggplot(data_All, aes(x=flank_eff, y=TOL_time)) + 
  geom_point() +
  geom_smooth(method="lm", color="purple") + 
  ggtitle("Correlation between flanker effect and Tower of London response time") +
  xlab("Flanker effect (Incongruent - Congruent RT)") +
  ylab("Tower of London overall respnose time") +
  theme_few()
flank.TOLtime.cor

cor.test(data_All$flank_eff, data_All$TOL_time)
## 
##  Pearson's product-moment correlation
## 
## data:  data_All$flank_eff and data_All$TOL_time
## t = 0.24055, df = 144, p-value = 0.8102
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1428720  0.1818977
## sample estimates:
##        cor 
## 0.02004152
flank.Switch.cor <- ggplot(data_All, aes(x=flank_eff, y=switchEff)) + 
  geom_point() +
  geom_smooth(method="lm", color="purple") + 
  ggtitle("Correlation between flanker effect and switcher effect") +
  xlab("Flanker effect (Incongruent - Congruent RT)") +
  ylab("Switcher effect (Predictable RT - Random RT)") +
  theme_few()
flank.Switch.cor

cor.test(data_All$flank_eff, data_All$switchEff)
## 
##  Pearson's product-moment correlation
## 
## data:  data_All$flank_eff and data_All$switchEff
## t = 1.2224, df = 136, p-value = 0.2237
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06396889  0.26670890
## sample estimates:
##       cor 
## 0.1042503
TOL.Switch.cor <- ggplot(data_All, aes(x=TOL_acc, y=switchEff)) + 
  geom_point() +
  geom_smooth(method="lm", color="purple") + 
  ggtitle("Correlation between Tower of London accuracy and switcher effect") +
  xlab("Tower of London overall accuracy") +
  ylab("Switcher effect (Predictable RT - Random RT)") +
  theme_few()
TOL.Switch.cor

cor.test(data_All$TOL_acc, data_All$switchEff)
## 
##  Pearson's product-moment correlation
## 
## data:  data_All$TOL_acc and data_All$switchEff
## t = 0.41847, df = 141, p-value = 0.6762
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1296790  0.1982219
## sample estimates:
##        cor 
## 0.03521926
# center all key variables
# first convert to tibble

colnames(data_All)[1] <- "Subject"
rt_wide <- read.csv("/Users/Kayleigh/dissertation/DataAnalysis/Exp2/CatLearning/rt_standardized.csv")
data_All <- merge(data_All, rt_wide, by="Subject")

data_All <- as_tibble(data_All)

data_All$flanker_cent <- scale(data_All$flank_eff)
data_All$TOL_acc_cent <- scale(data_All$TOL_acc)
data_All$TOL_time_cent <- scale(data_All$TOL_time)
data_All$TOL_first_cent <- scale(data_All$TOL_first)
data_All$switch_cent <- scale(data_All$switchEff)
dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=flanker_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=flanker_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=switch_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=switch_cent, y=ashby.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=flanker_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=flanker_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=switch_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=switch_cent, y=sloutsky.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=flanker_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=flanker_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_acc_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_time_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=TOL_first_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="hypothesis-testing") %>% 
  ggplot(. , aes(x=switch_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

dplyr::filter(data_All, System=="associative") %>% 
  ggplot(. , aes(x=switch_cent, y=tt.t)) + 
  geom_point() + 
  geom_smooth(method="lm", se=FALSE)

# ashby models

ashby.mod.0 <- lmer(ashby.t ~ (1|Subject), data_All)
summary(ashby.mod.0)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ashby.t ~ (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 564.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.43902 -0.65363 -0.05137  0.71451  2.09603 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.3626   0.6022  
##  Residual             0.6268   0.7917  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.01112    0.08141  -0.137
ashby.mod.1 <- lmer(ashby.t ~ System + 
                             (1|Subject), data_All)
summary(ashby.mod.1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ashby.t ~ System + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 501.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.3199 -0.4637  0.0354  0.5205  2.2489 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.5104   0.7144  
##  Residual             0.3311   0.5754  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.37546    0.09083   4.133
## Systemhypothesis-testing -0.77315    0.08058  -9.595
## 
## Correlation of Fixed Effects:
##             (Intr)
## Systmhypth- -0.444
ashby.mod.2 <- lmer(ashby.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent + TOL_time_cent + TOL_first_cent + 
                             (1|Subject), data_All)
summary(ashby.mod.2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ashby.t ~ System + flanker_cent + switch_cent + TOL_acc_cent +  
##     TOL_time_cent + TOL_first_cent + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 443.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4613 -0.4589  0.0504  0.5249  2.0237 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.4135   0.6431  
##  Residual             0.3219   0.5673  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.35628    0.08970   3.972
## Systemhypothesis-testing -0.78009    0.08365  -9.326
## flanker_cent              0.11683    0.08191   1.426
## switch_cent               0.04798    0.07958   0.603
## TOL_acc_cent              0.17282    0.10080   1.715
## TOL_time_cent             0.48757    0.28061   1.738
## TOL_first_cent           -0.24566    0.28699  -0.856
## 
## Correlation of Fixed Effects:
##             (Intr) Systm- flnkr_ swtch_ TOL_c_ TOL_t_
## Systmhypth- -0.466                                   
## flanker_cnt  0.036  0.000                            
## switch_cent  0.003  0.000 -0.106                     
## TOL_acc_cnt -0.053  0.000  0.083  0.015              
## TOL_tim_cnt -0.043  0.000 -0.002  0.039  0.530       
## TOL_frst_cn  0.033  0.000  0.008 -0.065 -0.562 -0.960
ashby.mod.3 <- lmer(ashby.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent +  
                             (System:flanker_cent) + (System:switch_cent) + (System:TOL_acc_cent) + 
                             (1|Subject), data_All)
summary(ashby.mod.3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ashby.t ~ System + flanker_cent + switch_cent + TOL_acc_cent +  
##     (System:flanker_cent) + (System:switch_cent) + (System:TOL_acc_cent) +  
##     (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 457
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.3151 -0.5224  0.0146  0.5346  2.1022 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.4754   0.6895  
##  Residual             0.3226   0.5679  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                                        Estimate Std. Error t value
## (Intercept)                            0.370826   0.093356   3.972
## Systemhypothesis-testing              -0.780202   0.083938  -9.295
## flanker_cent                           0.129523   0.096507   1.342
## switch_cent                           -0.003216   0.093242  -0.034
## TOL_acc_cent                           0.144230   0.098164   1.469
## Systemhypothesis-testing:flanker_cent -0.036312   0.086772  -0.418
## Systemhypothesis-testing:switch_cent   0.138661   0.083836   1.654
## Systemhypothesis-testing:TOL_acc_cent -0.015885   0.088262  -0.180
## 
## Correlation of Fixed Effects:
##                       (Intr) Systm- flnkr_ swtch_ TOL_c_
## Systmhypth-           -0.450                            
## flanker_cnt            0.042 -0.019                     
## switch_cent            0.002 -0.001 -0.104              
## TOL_acc_cnt           -0.049  0.022  0.107 -0.030       
## Systmhypthss-tstng:f_ -0.019  0.042 -0.450  0.047 -0.048
## Systmhypthss-tstng:s_ -0.001  0.002  0.047 -0.450  0.014
## Syst-:TOL__            0.022 -0.049 -0.048  0.014 -0.450
##                       Systmhypthss-tstng:f_ Systmhypthss-tstng:s_
## Systmhypth-                                                      
## flanker_cnt                                                      
## switch_cent                                                      
## TOL_acc_cnt                                                      
## Systmhypthss-tstng:f_                                            
## Systmhypthss-tstng:s_ -0.104                                     
## Syst-:TOL__            0.107                -0.030
# sloutsky models

sloutsky.mod.0 <- lmer(sloutsky.t ~ (1|Subject), data_All)
summary(sloutsky.mod.0)
## Linear mixed model fit by REML ['lmerMod']
## Formula: sloutsky.t ~ (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 572.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.44707 -0.64353 -0.00053  0.59277  2.09420 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.2985   0.5464  
##  Residual             0.7058   0.8401  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) -0.007642   0.079914  -0.096
sloutsky.mod.1 <- lmer(sloutsky.t ~ System + 
                             (1|Subject), data_All)
summary(sloutsky.mod.1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: sloutsky.t ~ System + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 543.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.34317 -0.58589 -0.00589  0.54926  1.94749 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.3912   0.6255  
##  Residual             0.5203   0.7213  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.30102    0.09453   3.184
## Systemhypothesis-testing -0.61733    0.10101  -6.112
## 
## Correlation of Fixed Effects:
##             (Intr)
## Systmhypth- -0.534
sloutsky.mod.2 <- lmer(sloutsky.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent + TOL_time_cent + TOL_first_cent + 
                             (1|Subject), data_All)
summary(sloutsky.mod.2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## sloutsky.t ~ System + flanker_cent + switch_cent + TOL_acc_cent +  
##     TOL_time_cent + TOL_first_cent + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 498.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.46401 -0.53755 -0.00954  0.54047  2.15312 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.3774   0.6144  
##  Residual             0.5319   0.7293  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.26376    0.09971   2.645
## Systemhypothesis-testing -0.60135    0.10753  -5.592
## flanker_cent             -0.08698    0.08668  -1.004
## switch_cent               0.03774    0.08422   0.448
## TOL_acc_cent              0.08036    0.10667   0.753
## TOL_time_cent            -0.03625    0.29696  -0.122
## TOL_first_cent            0.27882    0.30372   0.918
## 
## Correlation of Fixed Effects:
##             (Intr) Systm- flnkr_ swtch_ TOL_c_ TOL_t_
## Systmhypth- -0.539                                   
## flanker_cnt  0.035  0.000                            
## switch_cent  0.003  0.000 -0.106                     
## TOL_acc_cnt -0.051  0.000  0.083  0.015              
## TOL_tim_cnt -0.041  0.000 -0.002  0.039  0.530       
## TOL_frst_cn  0.032  0.000  0.008 -0.065 -0.562 -0.960
sloutsky.mod.3 <- lmer(sloutsky.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent +  
                             (System:flanker_cent) + (System:switch_cent) + (System:TOL_acc_cent) + 
                             (1|Subject), data_All)
summary(sloutsky.mod.3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## sloutsky.t ~ System + flanker_cent + switch_cent + TOL_acc_cent +  
##     (System:flanker_cent) + (System:switch_cent) + (System:TOL_acc_cent) +  
##     (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 500
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.34263 -0.55665  0.05163  0.46018  2.02046 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.4467   0.6683  
##  Residual             0.4853   0.6966  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                                       Estimate Std. Error t value
## (Intercept)                            0.26491    0.10089   2.626
## Systemhypothesis-testing              -0.58850    0.10296  -5.716
## flanker_cent                          -0.03825    0.10429  -0.367
## switch_cent                            0.09382    0.10076   0.931
## TOL_acc_cent                           0.32268    0.10608   3.042
## Systemhypothesis-testing:flanker_cent -0.10941    0.10643  -1.028
## Systemhypothesis-testing:switch_cent  -0.06245    0.10283  -0.607
## Systemhypothesis-testing:TOL_acc_cent -0.35355    0.10826  -3.266
## 
## Correlation of Fixed Effects:
##                       (Intr) Systm- flnkr_ swtch_ TOL_c_
## Systmhypth-           -0.510                            
## flanker_cnt            0.042 -0.021                     
## switch_cent            0.002 -0.001 -0.104              
## TOL_acc_cnt           -0.049  0.025  0.107 -0.030       
## Systmhypthss-tstng:f_ -0.021  0.042 -0.510  0.053 -0.055
## Systmhypthss-tstng:s_ -0.001  0.002  0.053 -0.510  0.015
## Syst-:TOL__            0.025 -0.049 -0.055  0.015 -0.510
##                       Systmhypthss-tstng:f_ Systmhypthss-tstng:s_
## Systmhypth-                                                      
## flanker_cnt                                                      
## switch_cent                                                      
## TOL_acc_cnt                                                      
## Systmhypthss-tstng:f_                                            
## Systmhypthss-tstng:s_ -0.104                                     
## Syst-:TOL__            0.107                -0.030
# tax-them models

tt.mod.0 <- lmer(tt.t ~ (1|Subject), data_All)
summary(tt.mod.0)
## Linear mixed model fit by REML ['lmerMod']
## Formula: tt.t ~ (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 531.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.07819 -0.43346  0.02957  0.53689  2.14763 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.5826   0.7633  
##  Residual             0.3956   0.6290  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.01809    0.08747  -0.207
tt.mod.1 <- lmer(tt.t ~ System + 
                             (1|Subject), data_All)
summary(tt.mod.1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: tt.t ~ System + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 523.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.03465 -0.50172  0.02106  0.46073  2.43003 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.6018   0.7758  
##  Residual             0.3572   0.5977  
## Number of obs: 204, groups:  Subject, 102
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.12670    0.09697   1.307
## Systemhypothesis-testing -0.28959    0.08369  -3.460
## 
## Correlation of Fixed Effects:
##             (Intr)
## Systmhypth- -0.432
tt.mod.2 <- lmer(tt.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent + TOL_time_cent + TOL_first_cent + 
                             (1|Subject), data_All)
summary(tt.mod.2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## tt.t ~ System + flanker_cent + switch_cent + TOL_acc_cent + TOL_time_cent +  
##     TOL_first_cent + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 484.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.22777 -0.47226  0.02059  0.46617  2.31665 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.5942   0.7708  
##  Residual             0.3760   0.6132  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                          Estimate Std. Error t value
## (Intercept)               0.11523    0.10304   1.118
## Systemhypothesis-testing -0.30414    0.09041  -3.364
## flanker_cent             -0.01875    0.09557  -0.196
## switch_cent               0.10202    0.09286   1.099
## TOL_acc_cent             -0.01612    0.11762  -0.137
## TOL_time_cent             0.30345    0.32743   0.927
## TOL_first_cent           -0.14683    0.33488  -0.438
## 
## Correlation of Fixed Effects:
##             (Intr) Systm- flnkr_ swtch_ TOL_c_ TOL_t_
## Systmhypth- -0.439                                   
## flanker_cnt  0.037  0.000                            
## switch_cent  0.003  0.000 -0.106                     
## TOL_acc_cnt -0.054  0.000  0.083  0.015              
## TOL_tim_cnt -0.044  0.000 -0.002  0.039  0.530       
## TOL_frst_cn  0.034  0.000  0.008 -0.065 -0.562 -0.960
tt.mod.3 <- lmer(tt.t ~ System + 
                             flanker_cent + switch_cent + TOL_acc_cent +  
                             (System:flanker_cent) + (System:switch_cent) + (System:TOL_acc_cent) + 
                             (1|Subject), data_All)
summary(tt.mod.3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## tt.t ~ System + flanker_cent + switch_cent + TOL_acc_cent + (System:flanker_cent) +  
##     (System:switch_cent) + (System:TOL_acc_cent) + (1 | Subject)
##    Data: data_All
## 
## REML criterion at convergence: 486.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.83323 -0.47297  0.02074  0.45537  2.42570 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Subject  (Intercept) 0.6148   0.7841  
##  Residual             0.3613   0.6011  
## Number of obs: 184, groups:  Subject, 92
## 
## Fixed effects:
##                                       Estimate Std. Error t value
## (Intercept)                            0.11676    0.10325   1.131
## Systemhypothesis-testing              -0.28875    0.08883  -3.250
## flanker_cent                          -0.09827    0.10673  -0.921
## switch_cent                            0.08612    0.10312   0.835
## TOL_acc_cent                           0.03979    0.10856   0.367
## Systemhypothesis-testing:flanker_cent  0.15195    0.09183   1.655
## Systemhypothesis-testing:switch_cent   0.05558    0.08872   0.626
## Systemhypothesis-testing:TOL_acc_cent -0.15437    0.09341  -1.653
## 
## Correlation of Fixed Effects:
##                       (Intr) Systm- flnkr_ swtch_ TOL_c_
## Systmhypth-           -0.430                            
## flanker_cnt            0.042 -0.018                     
## switch_cent            0.002 -0.001 -0.104              
## TOL_acc_cnt           -0.049  0.021  0.107 -0.030       
## Systmhypthss-tstng:f_ -0.018  0.042 -0.430  0.045 -0.046
## Systmhypthss-tstng:s_ -0.001  0.002  0.045 -0.430  0.013
## Syst-:TOL__            0.021 -0.049 -0.046  0.013 -0.430
##                       Systmhypthss-tstng:f_ Systmhypthss-tstng:s_
## Systmhypth-                                                      
## flanker_cnt                                                      
## switch_cent                                                      
## TOL_acc_cnt                                                      
## Systmhypthss-tstng:f_                                            
## Systmhypthss-tstng:s_ -0.104                                     
## Syst-:TOL__            0.107                -0.030